<!-- This is the gray box (beneath details of how last streak ended) to display any challenge statuses -->

	<div class="challenge-notification">
		<center>
			<table width=100%>  
				<!-- loop for each of the challenges sent to this user -->
				<%current_user.got_challenges.each do |ch|%>
				<%match = ch.match%>
				
			    <!-- If the match already started -->
				<%next if Time.now > match.begin_at%>
				<%match_not_placed =  current_user.bets.map{|b| b.match_id}.include?(ch.match_id.to_i)%>
					<% if !ch.hide_to_user %>
						<tr id='ch_<%=ch.id%>_to_user'>
							<td style="padding: 10px 2px 10px 10px">
								<%=fb_profile_pic ch.sender,{:size=>:square}%>
							</td>
							<td>
								<%if !match_not_placed%>
										<%=fb_name ch.sender%> sent you a <%=ch.amount%> WinPoints challenge -
										<%=link_to "see details","#",:onclick=>"showDialog('#{@call_back_url + "/friends_bet/gen_dialog?sid=" + match.id.to_s + "&uid=" + ch.sender.id.to_s + "&chid=" + ch.id.to_s}','Challenge Details','Accept','Cancel');return false" if Time.now < match.begin_at%>
								<%else%>
										<%=fb_name ch.sender%> sent you a <%=ch.amount%> WinPoints challenge -
										<%=link_to "see details","#",:onclick=>"showDialog('#{@call_back_url + "/friends_bet/gen_dialog?sid=" + match.id.to_s + "&uid=" + ch.sender.id.to_s + "&chid=" + ch.id.to_s}','Challenge Details','Accept','Cancel');return false" if Time.now < match.begin_at%>
								<%end%>
								<td style="padding: 0 10px 0 0">
									<%=link_to "[X]","#",:onclick=>"dismiss_ajax('" + @call_back_url + "','ch_to_user'," + ch.id.to_s + ");return false;",:clicktohide=>"ch_#{ch.id}_to_user"%>
								</td>
							</td>
					   </tr>
					<%end%>
				<%end%>
				
				
				<!-- loop for each of the challenges sent by this user -->
				<%current_user.sent_challenges.each do |ch|%>
				<%match = ch.match%>
				<%next if !ch.match or Time.now > match.begin_at%>
				<%match_not_placed =  current_user.bets.map{|b| b.match_id}.include?(ch.match_id.to_i)%>
					<% if !ch.hide_from_user %>	
						<tr id='ch_<%=ch.id%>_from_user'>
							<td style="padding: 10px 2px 10px 10px">
								<%=fb_profile_pic ch.sender,{:size=>:square}%>
							</td>
							<td>
								<%if !match_not_placed%>
										<%=fb_name ch.sender%> sent <%=fb_name ch.goter%> a <%=ch.amount%> WinPoints challenge -
										<%=link_to "see details","#",:onclick=>"showDialog('#{@call_back_url + "/friends_bet/gen_dialog?sid=" + match.id.to_s + "&uid=" + ch.sender.id.to_s + "&chid=" + ch.id.to_s}','Challenge Details','Accept','Cancel');return false" if Time.now < match.begin_at%>
								<%else%>
									<%=fb_name ch.sender%> sent <%=fb_name ch.goter%> a <%=ch.amount%> WinPoints challenge -
									<%=render(:partial=>'friends_bet/ch_details',:locals=>{:ch=>ch,:u=>ch.sender}).gsub("<br/>"," ")%>
								<%end%>
								<td style="padding: 0 10px 0 0">
									<%=link_to "[X]","#",:onclick=>"dismiss_ajax('" + @call_back_url + "','ch_from_user'," + ch.id.to_s + ");return false;",:clicktohide=>"ch_#{ch.id}_from_user"%>
								</td>
							</td>
					   </tr>
					<%end%>   
				<%end%>

				<!-- challenge results display zone -->
				<%if current_user.result_got_ches.size > 0%>
					<%current_user.result_got_ches.each do |ch|%>
						<% if !ch.hide_from_user_result %>
							<tr id='ch_<%=ch.id%>_from_user_result'>
								<td style="padding: 10px 2px 10px 10px">
									<%=fb_profile_pic ch.sender,{:size=>:square}%>
								</td>
								<td>
									<%=current_user.bet(ch.match).win? ? "<font color=green>WIN</font>" : "<font color=red>LOSE</font>"%>: <%=ch.amount%> WinPoints on <%=ch.match.home_team.displayed_name%> vs. <%=ch.match.away_team.displayed_name%> bet with <%=fb_name ch.sender%>
								</td>
								<td style="padding: 0 10px 0 0">
									<%=link_to "[X]","#",:onclick=>"dismiss_ajax('" + @call_back_url + "','ch_from_user_result'," + ch.id.to_s + ");return false;",:clicktohide=>"ch_#{ch.id}_from_user_result"%>
								</td>
							</tr>
						<%end%>
					<%end%>
				<%end%>
			  
				<%if current_user.result_sent_ches.size > 0%>
					<%current_user.result_sent_ches.each do |ch|%>
						<% if !ch.hide_to_user_result %>
							<tr id='ch_<%=ch.id%>_to_user_result'>
								<td style="padding: 10px 2px 10px 10px">
									<%=fb_profile_pic ch.goter,{:size=>:square}%>
	
								</td>
								<td>
									<%=current_user.bet(ch.match).win? ? "<font color=green>WIN</font>" : "<font color=red>LOSE</font>"%>: <%=ch.amount%> WinPoints on <%=ch.match.home_team.displayed_name%> vs. <%=ch.match.away_team.displayed_name%> bet with <%=fb_name ch.goter%>
								</td>
								<td style="padding: 0 10px 0 0">
									<%=link_to "[X]","#",:onclick=>"dismiss_ajax('" + @call_back_url + "','ch_to_user_result'," + ch.id.to_s + ");return false;",:clicktohide=>"ch_#{ch.id}_to_user_result"%>
								</td>
							</tr>
						<%end%>
					<%end%>
				<%end%>
			</table>
		</center>
	</div>

